(function(){

  var Dataset = Basis.Data.Dataset;

  var Subtree = Dataset.Merge.subclass({
    init: function(config){
      new Dataset.MapReduce({
        source: this,
        result: new Dataset.Merge({
          handler: this.listen.source,
          handlerContext: this
        }),
        map: function(object){
          return App.Type.bemSplit.getSubset(object, true); // create subset anyway
        },
        addMemberRef: function(member, object){
          this.result.addSource(member);
        },
        removeMemberRef: function(member, object){
          this.result.removeSource(member);
        },
        listen: {
          source: {
            destroy: function(){
              this.destroy();
            }
          }
        }
      });

      Dataset.Merge.prototype.init.call(this, config);
    }
  });

  var Complete = Dataset.Merge.subclass({
    init: function(config){
      new Dataset.MapReduce({
        source: this,
        map: Function.getter('getParent()'),

        handler: this.listen.source,
        handlerContext: this,

        listen: {
          source: {
            destroy: function(){
              this.destroy();
            }
          }
        }
      });

      Dataset.Merge.prototype.init.call(this, config);
    }
  });

  Basis.namespace('App.Type.Dataset').extend({
    Complete: Complete,
    Subtree: Subtree
  });

})();